Part 2: Quarto Introduction

OCTRI-BERD Workshop July 2025

Author
Affiliation

Jessica Minnier, Meike Niederhausen

OHSU-PSU School of Public Health

Published

July 17, 2025

This file contains just the code from the Part 2: Quarto Introduction slides. Please see the slides for context and more detailed information.

1 3 types of Quarto content: text

  1. Text, lists, images, tables, links
  2. Code chunks
  3. YAML metadata

1.1 Formatting text

This text is in italics, but so is this text.

Bold also has 2 options

Should this be deleted?

Needsuper orsub scripts?

Code is often formatted as verbatim

This is a block quote.

1.2 Headers

Organize your documents using headers to create sections and subsections

Use # at the beginning of the line to create headers

Make sure there is no space before the #, and there IS a space after the # in order for the header to work properly.

Above we already saw level one # and two ## headers be used.
Below are more levels of headers:

1.2.1 Header 3

1.2.1.1 Header 4

1.2.1.1.1 Header 5
1.2.1.1.1.1 Header 6

1.3 Unnumbered lists

  • This is an unnumbered list
    • with sub-items
      • and sub-sub-items,
        • or even deeper.
  • You can use characters *, +, and - interchangeably to create lists.
    • The order of the
      • character types is not important
      • and character types can be repeated.

What is important is the spacing!

  • indent each
    • sub-level with a tab and make sure
    • there is a space between the character starting the list and the first bit of text, *otherwise the text won’t be a new bullet in the list, such as this line.

Also, if you do not have an empty line + before starting a list, + then the output will be continuous text - instead of bullet points.

1.4 Numbered lists

  1. This is a Numbered list,
  2. which can have
    1. sub
    2. items
      1. and
      2. sub-sub-items.

You can also

  1. create numbered lists
  2. by repeating
  3. 1. over and over again.
    1. Each bullet
    2. can start with
    3. 1. or i.
      1. or a.,
      2. in theory…

When lists get interrupted

  1. the numbering restarts
  2. at 1. though.

To create a list

  1. whose numbering

does not

  1. get interrupted,
  2. use (@).

1.5 To-do lists

  • You can also create tasks, or to-do lists, with Quarto.
  • Note that you can check off boxes in the slides!

Topics to cover:

1.6 Practice

  1. Part 1
    1. Using the visual editor, practice formatting text in your qmd file, such as making text bold, italicized, and in code format.
    2. Add 1st, 2nd, and 3rd level headers
    3. Add a list with a
      • sub-list (bullet and/or numbered)
    4. Add a table
    5. Add whatever else you are interested in!
  2. Part 2
    1. Switch back to the Source editor and examine the markdown code that was used for the formatting.

Questions: Share in the chat:

  1. What went smoothly?
  2. What hurdles did you encounter?

1.8 Images (1/2)

  • Add an image with a simple ![](filepath)
  • The filepath can be an image on your computer or a url for an image on the web.
  • So that you can render this html file, we are using an image on the web below:

You can add html image options to change the width or height:

Specifying width in terms of pixels:

Specifying height in inches:

Specifying width as a percent of the original image size:

1.9 Images (2/2)

Add captions, links, and align

  • Add caption text (& align left):

Caption text
  • Add caption text that is linked to OHSU webpage (& align center):
  • Logo image itself is linked to OHSU webpage (& align right):

OHSU Logo

1.10 Tabsets

You can add tabbed content to webpages or slides using the standard Quarto syntax for tabsets.

  • Each header creates a new tab.
    • The header level (# vs ## vs ###, etc.) doesn’t matter, but they all have to be the same level to create new tabsets.
    • Here we used ### level header so that the tabset appears nested within the contents of the slide, which is ## level.

Content for Tab A

Content for Tab B

Content for Tab C

1.11 Callout Blocks ⚠️

Tip

Callouts are an excellent way to draw attention to specific pieces of information.

Note

They are especially useful for notes, warnings, or tips.

Important

You create them using fenced divs ::: with a special class.

Caution

There are 5 types of callouts.

Warning

It is tempting to overdo it with callout boxes!

1.11.1 Customizing Callout Blocks ⚠️

Tip with different title

You can change the title of any type of callout box by adding ## New title right below the first line of the callout.

Note

You can omit the icon of any type of callout box by adding icon=false within the {} of the first line of the callout.

  • If you look at the html file (not the slides), you will see that the content of this callout is “folded” and needs to be expanded by the user to see it.
  • Use collapse="true" if you want it collapsed by default, and
  • collapse="false" to make it expanded by default.

1.12 Tables

One benefit of using or switching over to the Visual editor is that it is much easier to add tables.

Name Date Measure
Jessica 02/04/25 9.3
Meike 01/03/25 10.1
BERD 🐦 10.5
Important
  • When creating tables summarizing data or showing regression output, this is NOT the way to create them.
  • Use code chunks and table options within R to create them instead.

1.13 Equations with LaTeX

  • Mathematical equations and symbols can be included using LaTeX, both as inline equations or centered display equations

  • Use single $ for inline equations: \(y=\beta_0 + \beta_1x + \varepsilon\)

  • Use double $$ for centered display equations:

\[\hat{y}= \frac{3}{7} + 5 \textrm{age} + 3^2 \cdot \textrm{height}\]

2 3 types of Quarto content: code

2.1 Code chunks

  • See slides for material on creating and running code chunks.

2.2 Code chunk options

  • eval determines whether the R code is run or not.
  • The default is true.
  • When set to false, the code is not run but still displayed in the output:

#| eval: true

Code
y <- 1:10
mean(y)
[1] 5.5

#| eval: false

Code
y <- 1:10
mean(y)
  • echo determines whether the R code is displayed or not.
  • The default is true. When set to false, the code is not displayed in the output but the output is (if eval is set to true):

#| echo: true

Code
y <- 1:10
mean(y)
[1] 5.5

#| echo: false

[1] 5.5
  • warning: do you want R’s warnings include in your output?
  • message: do you want R’s messages include in your output?

For a complete list of options, see the Quarto reference page for Code Cells: Knitr. In particular the sections on Code Output and Cell Output.

  • Usually you want most of your document to have the same code chunk options.
  • You can set these options in the YAML of the Quarto file (next topic!).

3 3 types of Quarto content: YAML

See the slides for information about the YAML.

3.1 Change the output file type

  • The YAML specifies the format of the output file:
    • html, Word, pdf, slides, website, book, etc.
  • This is done by changing the format: option
---
title: "My first Quarto file"
author: "Meike"
date: "9/25/2023"
format: html
editor: visual
---
Output format YAML
html format: html
Word format: docx
pdf1 format: pdf
html slides format: revealjs
PPT slides format: pptx

3.2 Practice

  • Change the format of the qmd file to revealjs and render the file.
    • How do the slides look?
    • What in the code determines when a new slide is created?
  • Change the format of the qmd file to pptx and render the file.
    • How do the slides look? Which styling options worked and which did not?
    • What in the code determines when a new slide is created?
  • Change the format of the qmd file to docx and render the file.
    • How does the Word doc look? Which styling options worked and which did not?

3.3 YAML customizations

  • Below are some YAML options to customize your html file.
  • Download from GitHub the file part2_intro_code_yaml_extra.qmd to render it on your computer.
    • You can view the rendered version online. This will look different from on your computer though since the workshop’s website’s setting are being applied to it.
  • Learn about many more YAML options from Quarto’s HTML Options page.
---
title: "Part 2: Quarto Introduction"
pagetitle: "Part 2: Quarto Introduction"
subtitle: "OCTRI-BERD Workshop July 2025"
author: "Jessica Minnier, Meike Niederhausen"
institute: "OHSU-PSU School of Public Health"
date: "7/17/25"
format:
  html:
    link-external-newwindow: true  # open links in a new tab
    toc: true                      # create a table of contents
    number-sections: true         # numbers header sections
    embed-resources: true          # IMPORTANT! Creates a standalone html file that other can view without needing additional files.
    code-fold: show                # true collapses all code chunks; show shows the code
    code-tools: true               # creates menu at top of html to toggle code folding
execute:
  echo: true                      # show all code in code chunks
  eval: true                      # run all code in code chunks 
editor: source                    # other options is visual
# editor_options: 
#   chunk_output_type: console      # Code output shown in console instead of inline
---

Footnotes

  1. pdf requires LaTeX installation↩︎